<template>
    <el-dialog v-if="info" :title="title?title:info.userInfo.name+'的个人简历'" width="1080px" top="4vh" lock-scroll
               custom-class="info-dialog" :visible.sync="dialogVisible">
        <div class="info-panel">
            <div class="info clearfix">
                <div class="fl clearfix">
                    <el-avatar :src="info.userInfo.photoId_dictText" icon="el-icon-user-solid"
                               class="avatar fl ml10 mr15"/>
                    <div class="fl info-detail">
                        <h1 class="name">
                            <span>{{ info.userInfo.name }}</span>
                            <!-- <span class="status f16 text-666 ml10">通过初筛</span> -->
                            <div class="fr">
                                <el-button v-if="!info.notransport" type="text" @click.native="transPort(null)">
                                    <i class="el-icon-share"/>
                                    转发
                                </el-button>
                            </div>
                        </h1>
                        <p class="info">
                            <span class="text-999">{{ info.userInfo.sex == 1 ? '男' : '女' }}</span>
                            <el-divider direction="vertical"/>
                            <span class="text-999">{{ info.userInfo.age }}</span>
                            <el-divider direction="vertical"/>
                            <span class="text-999">{{ info.userInfo.liveCity_dictText }}</span>
                            <el-divider direction="vertical"/>
                            <span class="text-999">{{ info.userInfo.workYears }}年经验</span>
                        </p>
                        <div class="text-333 info-contact"><i class="iconfont iconshouji2"/><span
                            class="mr20">{{ info.userInfo.phone }}</span><i class="iconfont iconyouxiang1"/><span
                            class="ml5">{{ info.userInfo.email }}</span></div>
                    </div>
                </div>
                <div class="fr"/>
            </div>
            <div class="info-body clearfix" :class="[notab?'notab':'']">
                <div class="fl pdf-wrapper" :style="{width:showTimeline?'740px':'100%'}">
                    <div v-if="!notab">
                        <el-tabs v-model="activeIndex" class="mt20" type="card" @tab-click="handleClick">
                            <el-tab-pane v-if="info.showAll||(info.type == 0 && info.lanType == 0)"
                                         :label="`在线中文简历(${list[0] ? list[0].resumeType_dictText : ''})`" name="0">
                                <div class="tab-body">
                                    <div class="pdf-container" :style="{width:showTimeline?'700px':'100%'}">
                                        <pdf v-if="resetPdf"
                                             :prams="{ userId: info.userInfo.userId, type: '0', langType: '0',responseType: true,jobId: info.jobInfo ?info.jobInfo.id : ''}"
                                             :data-id="info.dataId"/>
                                    </div>
                                </div>
                            </el-tab-pane>
                            <el-tab-pane v-if="info.showAll||(info.type == 0 && info.lanType == 1)"
                                         :label="`在线英文简历(${resumeTypeEn == 0 ? '无' : resumeTypeEn == 1 ? '社招': '校招'})`"
                                         name="1" :disabled="resumeTypeEn == 0">
                                <div class="tab-body">
                                    <div class="pdf-container" :style="{width:showTimeline?'700px':'100%'}">
                                        <pdf v-if="resetPdf"
                                             :prams="{ userId: info.userInfo.userId, type: '0', langType: '1',responseType: true,jobId: info.jobInfo ?info.jobInfo.id : '' }"
                                             :order="0" :data-id="info.dataId" @popres="popres"/>
                                    </div>
                                </div>
                            </el-tab-pane>
                            <el-tab-pane v-if="info.showAll||info.type == 1" label="附件简历" name="2"
                                         :disabled="disabled[1]?true:false">
                                <div class="tab-body">
                                    <div class="pdf-container" :style="{width:showTimeline?'700px':'100%'}">
                                        <pdf v-if="resetPdf" :prams="{ userId: info.userInfo.userId, type: '1'}"
                                             :order="1" :data-id="info.dataId" @popres="popres"/>
                                    </div>
                                </div>
                            </el-tab-pane>
                            <!-- 应聘记录 -->
                            <el-tab-pane v-if="showHis" label="应聘记录" name="3">
                                <div class="tab-body">
                                    <el-table
                                        ref="table"
                                        :data="list"
                                        style="width: 100%"
                                        max-height="360px"
                                    >
                                        <!-- <el-table-column
                                          type="selection"
                                          width="55"
                                          fixed="left"
                                        /> -->
                                        <el-table-column
                                            prop="deliveryInfo.createTime"
                                            label="投递日期"
                                            width="180"
                                            align="center"
                                        />
                                        <!-- <el-table-column
                                          prop="enInfo.enName"
                                          label="投递公司"
                                          width="180"
                                          align="center"
                                        /> -->
                                        <el-table-column
                                            prop="jobInfo.jobName"
                                            label="职位"
                                            width="180"
                                            align="center"
                                        />
                                        <el-table-column
                                            label="职位发布源"
                                            width="180"
                                            align="center"
                                        >
                                            <template slot-scope="{row}">
                                                {{ row.jobInfo.sysFrom == 1 ? '企业发布-' : '平台发布-' }}
                                                {{ row.jobInfo.bsType ? '专场职位' : '普通职位' }}
                                            </template>
                                        </el-table-column>
                                        <el-table-column
                                            label="状态"
                                            width="100"
                                            align="center"
                                        >
                                            <template slot-scope="{row}">
                                                {{ stateFilter(row.deliveryInfo.state) }}
                                            </template>
                                        </el-table-column>
                                        <el-table-column
                                            label="操作"
                                            fixed="right"
                                            align="center"
                                            width="250px"
                                        >
                                            <template slot-scope="{row}">
                                                <el-button type="text"
                                                           @click="viewDetail(row.deliveryInfo.userId,row.jobInfo.id)">
                                                    详情
                                                </el-button>
                                                <el-button type="text" class="el-link el-link--success"
                                                           @click.native="transPort(row.jobInfo.jobName,row.deliveryInfo.resumeId,row.jobInfo.id)">
                                                    转发
                                                </el-button>
                                                <!-- <el-cascader
                                                  v-if="resumeHandlerData[row.deliveryInfo.state]&&resumeHandlerData[row.deliveryInfo.state].children"
                                                  style="width: 120px;"
                                                  size="mini"
                                                  placeholder="移动到"
                                                  :options="resumeHandlerData[row.deliveryInfo.state].children"
                                                  class="ml10"
                                                  @change="e=>dropdownChange(e,row.deliveryInfo.id)"
                                                /> -->
                                                <!-- <el-dropdown trigger="click" class="ml10" @command="dropdownChange">
                                                  <span class="el-dropdown-link el-button--text fn" style="outline: none;cursor: pointer;">
                                                    移动到<i class="el-icon-arrow-down el-icon--right" />
                                                  </span>
                                                  <el-dropdown-menu slot="dropdown">
                                                    <el-dropdown-item v-for="(item,index) in jobState" :key="index" :disabled="false" :command="item.value">{{ item.label }}</el-dropdown-item>
                                                  </el-dropdown-menu>
                                                </el-dropdown>
                                                <el-dropdown v-if="false" trigger="click" class="ml10" @command="reasonChange">
                                                  <span class="el-dropdown-link el-button--text fn" style="outline: none;cursor: pointer;">
                                                    请选择原因<i class="el-icon-arrow-down el-icon--right" />
                                                  </span>
                                                  <el-dropdown-menu slot="dropdown">
                                                    <el-dropdown-item v-for="(item,index) in loseReason" :key="index" :disabled="false" :command="item.value">{{ item.label }}</el-dropdown-item>
                                                  </el-dropdown-menu>
                                                </el-dropdown> -->
                                            </template>
                                        </el-table-column>
                                    </el-table>
                                    <pagination
                                        v-show="total>0"
                                        :total="total"
                                        next-text="下一页"
                                        layout="prev, pager, next, jumper"
                                        :page.sync="listQuery.pageNo"
                                        :limit.sync="listQuery.pageSize"
                                        @pagination="getList"
                                    />
                                </div>
                            </el-tab-pane>
                        </el-tabs>
                    </div>
                    <div v-if="notab">
                        <div class="tab-body notab">
                            <div class="pdf-container" :style="{width:showTimeline?'700px':'100%'}">
                                <!-- <pdf
                                  v-for="i in numPages"
                                  :key="i"
                                  :src="src"
                                  :page="i"
                                  style="display: block; width: 100%"
                                /> -->
                            </div>
                        </div>
                    </div>
                </div>
                <div v-if="showTimeline" class="fr timeline-Wrap">
                    <el-button v-if="showHis" icon="el-icon-close" size="small" type="primary" circle class="close-btn"
                               @click.native="showTimeline=false"/>
                    <div class="info-timeline" :class="[notab?'notab':'']">
                        <template>
                            <no-data v-if="!records.length"/>
                            <el-timeline v-else>
                                <el-timeline-item v-for="(item,index) in records" :key="index"
                                                  :color="!index?'#348CE8':''">
                                    <!-- <el-collapse>
                                      <el-collapse-item>
                                        <template slot="title">
                                          <div class="timeline-title">
                                            <span class="f16 text-333">{{ item.title }}</span>
                                            <p class="item-time text-ccc f12">{{ item.createTime }}</p>
                                          </div>
                                        </template>
                                        <div>与现实生活一致：与现实生活的流程、逻辑保持一致，遵循用户习惯的语言和概念；</div>
                                        <div>在界面中一致：所有的元素和结构需保持一致，比如：设计样式、图标和文本、元素的位置等。</div>
                                      </el-collapse-item>
                                    </el-collapse> -->
                                    <div class="timeline-title">
                                        <span class="f16 text-333">{{ item.title }}</span>
                                        <p class="item-time text-ccc f12">{{ item.createTime }}</p>
                                        <!-- <label class="timeline-label text-999 f12 ml10 active">{{ item.readFlag?'已读':'未读' }}</label> -->
                                    </div>
                                    <!-- <div class="timeline-item"> -->

                                    <!-- <ul class="timeline-content">
                                        <li class="content-item">
                                          <span class="item-title f12 text-999">录用时间</span>：
                                          <span class="item-content f12 text-666">2020-10-22 16:40</span>
                                        </li>
                                        <li class="content-item">
                                          <span class="item-title f12 text-999">上班地点</span>：
                                          <span class="item-content f12 text-666">郑州市 中原区 国家863中部软件园11号楼1206</span>
                                        </li>
                                        <li class="content-item">
                                          <span class="item-title f12 text-999">联系人</span>：
                                          <span class="item-content f12 text-666">李女士</span>
                                        </li>
                                        <li class="content-item">
                                          <span class="item-title f12 text-999">联系电话</span>：
                                          <span class="item-content f12 text-666">18956588899</span>
                                        </li>
                                        <li class="content-item">
                                          <span class="item-title f12 text-999">备注信息</span>：
                                          <span class="item-content f12 text-666">请着正装上班</span>
                                        </li>
                                      </ul> -->
                                    <!-- </div> -->
                                </el-timeline-item>
                            </el-timeline>
                        </template>
                    </div>
                </div>
            </div>
        </div>

        <!--    <div slot="footer" class="dialog-footer">
          <el-button @click="dialogVisible = false">
            取消
          </el-button>
          <el-button type="primary" @click="dialogVisible = false">
            确认
          </el-button>
        </div> -->
    </el-dialog>
</template>

<script>
import Pagination from '@/components/Pagination' // secondary package based on el-pagination
import noData from '@/components/noData'
import pdf from './pdf.vue'
import {entryInfApplyList, editState} from '@/api/personnel'
import {enMessageList2} from '@/api/article'
import {mapState} from 'vuex'

export default {
    name: 'PdfDialog',
    components: {pdf, Pagination, noData},
    props: {},
    data() {
        return {
            title: '',
            value: '',
            resumeTypeEn: 0,//0无 1:社招 2:校招
            activeIndex: '0',
            dialogVisible: false,
            showHis: false, // 是否显示tab里应聘记录，
            showTimeline: false, // 显示右侧时间线
            notab: false, // 只有在线简历和时间线，没有tab切换
            list: [],
            records: [], // 面试记录
            total: 1,
            listQuery: {
                pageNo: 1,
                pageSize: 10,
                sort: false,
                userId: ''
            },
            info: null,
            resetPdf: false,
            disabled: [false, false],
            fun: {
                initial: (res) => {
                    console.log('initial', res)
                },
                lose: (res) => {
                    console.log('lose', res)
                },
                pass: (res) => {
                    console.log('pass', res)
                },
                interviewForm: (res) => {
                    console.log('interviewForm', res)
                },
                feedbackForm: (res) => {
                    console.log('feedbackForm', res)
                },
                employForm: (res) => {
                    console.log('employForm', res)
                },
                success: (res) => {
                    console.log('success', res)
                },
                absent: (res) => {
                    console.log('absent', res)
                }
            }
        }
    },
    computed: {
        ...mapState({
            jobState: state => state.app.jobState,
            loseReason: state => state.app.loseReason,
            resumeHandler: state => state.app.resumeHandler,
            resumeHandlerData: state => state.app.resumeHandlerData
        })
    },
    watch: {
        dialogVisible(e) {
            if (!e) {
                this.resetPdf = false
                this.activeIndex = '0'
                this.showTimeline = false
                this.disabled = [false, false]
            }
        }
    },
    mounted() {

    },
    methods: {
        stateFilter(e) {
            const item = this.resumeHandler.find(item => item.value == e)
            return item.label
        },
        popres(e) {
            this.disabled.splice(e, 1, true)
        },
        show(data, showHis, showTimeline, title) {
            this.resumeTypeEn = 0
            if (title) this.title = title
            this.info = data
            this.dialogVisible = true
            this.listQuery.userId = data.userInfo.userId
            if (data.type == 0) {
                this.activeIndex = data.lanType + ''
            } else {
                this.activeIndex = '2'
            }
            if (showHis) {
                this.showHis = true
                this.getList()
            }
            if (showTimeline) {
                this.showTimeline = true
                this.viewDetail(data.userInfo.userId, data.jobInfo.id)
            }
            this.resetPdf = true
        },
        // tab
        handleClick(tab, event) {
        },
        // 应聘记录
        getList() {
            entryInfApplyList(this.listQuery).then(response => {
                const list = response.result.records;
                let resumeTypes = {};
                list.forEach(e => {
                    resumeTypes[e.deliveryInfo.resumeId] = e.resumeType
                })
                let ert = Object.values(resumeTypes).find(item => item == 2)
                if (ert) {
                    this.resumeTypeEn = ert
                }
                this.list = list
                this.total = response.result.total
            })
        },
        viewDetail(userId, id) {
            this.showTimeline = true
            enMessageList2({userId, objId: id, type: 2}).then(response => {
                this.records = response.result.records
            })
        },
        //
        transPort(jobName, reId, jobId) {
            if (jobName) {
                this.$emit('transportShow', {name: this.info.userInfo.name, jobName, reId, jobId: jobId})
            } else {
                this.$emit('transportShow', {
                    name: this.info.userInfo.name,
                    jobName: this.info.jobInfo.jobName,
                    reId: this.info.resumeId
                })
            }
        },
        // 再次面试
        faceReturn() {
            this.$emit('interviewShow', {
                name: this.info.userInfo.name,
                id: this.info.userId,
                jobName: this.info.jobInfo.jobName,
                jobId: this.info.jobId,
                companyId: this.info.companyId,
                reId: this.info.resumeId,
                dataId: this.info.delId
            })
        },
        // 修改状态
        dropdownChange(e, id) {
            const item = this.resumeHandler.find(item => item.value === e[0])
            this.fun[item.btnKey](e.join(','))
        },
        reasonChange(e) {
            let dataId = ''
            if (this.showHis) {
                const ids = [];
                const selected = this.$refs.table.selection
                selected.forEach(item => {
                    ids.push(item.deliveryInfo.id)
                })
                dataId = ids.join(',')
            } else {
                dataId = this.info.delId
            }
            this.$confirm('确定修改状态吗？', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                editState({dataId, state: '2', type: e}).then(response => {
                    this.$message.success('修改成功！')
                    this.$emit('refresh')
                    if (this.showHis) this.getList()
                })
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消'
                })
            })
        }
    }
}
</script>

<style lang="scss" scoped>
.info-panel {
    padding: 20px;
    margin-top: 10px;
    border-top: 1px solid #ECECEC;

    ::v-deep .el-tabs__nav-wrap {
        padding: 0;
    }

    ::v-deep .el-tabs__content {
        background: none;
    }

    .info-detail {
        width: 930px;
    }

    .avatar {
        width: 80px;
        height: 80px;
        border-radius: 40px;
        line-height: 80px;
        font-size: 36px;
    }

    .name {
        font-size: 24px;
        line-height: 24px;
        margin: 0;
        padding: 0;
    }

    .info {
        margin: 12px 0;
    }

    .info-contact {
        i, span {
            display: inline-block;
            vertical-align: middle;
            height: 16px;
            line-height: 16px;

            &.iconfont {
                font-size: 15px;
                margin-right: 2px;
            }
        }
    }

    .info-body {
        &.notab {
            margin-top: 30px;
        }

        .pdf-wrapper {
            ::v-deep .el-tabs--card > .el-tabs__header {
                margin-bottom: 0;
            }

            .tab-body {
                width: 100%;
                padding: 20px;
                border: 1px solid #dfe4ed;
                border-top: 0;
                height: 460px;

                &.notab {
                    border: 1px solid #dfe4ed;
                }
            }

            .pdf-container {
                height: 420px;
                margin: 0 auto;
                overflow-y: auto;
                scrollbar-width: none; /* firefox */
                -ms-overflow-style: none; /* IE 10+ */
                &::-webkit-scrollbar {
                    display: none; /* Chrome Safari */
                }
            }
        }

        .timeline-Wrap {
            position: relative;

            .close-btn {
                position: absolute;
                right: 0;
                top: 20px;
            }

            .info-timeline {
                margin-top: 60px;

                &.notab {
                    margin-top: 0px;
                }

                width: 260px;
                height: 460px;
                overflow-y: auto;
                scrollbar-width: none; /* firefox */
                -ms-overflow-style: none; /* IE 10+ */
                .timeline-title {
                    line-height: 22px;

                    span {
                        display: inline-block;
                        vertical-align: middle;
                    }

                    .timeline-label {
                        height: 22px;
                        line-height: 22px;
                        background: #F3F3F3;
                        padding: 0 5px;
                        display: inline-block;
                        vertical-align: middle;
                        border-radius: 4px;

                        &.active {
                            background: #348CE8;
                            color: #fff;
                        }
                    }
                }

                .item-time {
                    margin-top: 5px;
                    margin-bottom: 0;
                }

                &::-webkit-scrollbar {
                    display: none; /* Chrome Safari */
                }

                ::v-deep.el-collapse {
                    border: 0;

                    .el-collapse-item__wrap {
                        border: 0;
                    }

                    .el-collapse-item__content {
                        padding-bottom: 0;
                    }

                    .el-collapse-item__header {
                        height: 60px;
                        line-height: 60px;
                        border: 0;
                    }
                }

                .timeline-content {
                    padding: 0;
                    margin: 0;
                    list-style: none;

                    .content-item {
                        margin-bottom: 8px;

                        .item-title {
                            width: 4em;
                            display: inline-block;
                            text-align: justify;
                            text-align-last: justify;
                        }
                    }
                }
            }
        }
    }
}

::v-deep .info-dialog .el-dialog__body {
    padding: 0;
}

.pagination-container {
    padding: 0;
    margin: 20px 0;
}
</style>
